﻿namespace Hidistro.UI.SaleSystem.Tags
{
    using Hidistro.Entities.Promotions;
    using Hidistro.Entities.Sales;
    using Hidistro.UI.Common.Controls;
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Threading;
    using System.Web.UI.WebControls;
using wnxd.javascript;

    public class Common_ShoppingCart_ProductList : AscxTemplatedWebControl
    {
        private DataList dataListShoppingCrat;
        private Panel pnlShopProductCart;
        public const string TagID = "Common_ShoppingCart_ProductList";

        public event DataListCommandEventHandler ItemCommand;

        private bool isNull = true;
        public Dictionary<string, List<ShoppingCartItemInfo>> promotions;

        public json NotSelect;
        public Common_ShoppingCart_ProductList()
        {
            base.ID = "Common_ShoppingCart_ProductList";
        }
        protected override void AttachChildControls()
        {
            this.dataListShoppingCrat = (DataList)this.FindControl("dataListShoppingCrat");
            this.pnlShopProductCart = (Panel)this.FindControl("pnlShopProductCart");
            this.pnlShopProductCart.Visible = false;
            this.dataListShoppingCrat.ItemCommand += new DataListCommandEventHandler(this.dataListShoppingCrat_ItemCommand);
        }

        public override void DataBind()
        {
            this.EnsureChildControls();
            if (this.dataListShoppingCrat.DataSource != null)
            {
                this.dataListShoppingCrat.DataBind();
            }
        }

        private void dataListShoppingCrat_ItemCommand(object source, DataListCommandEventArgs e)
        {
            this.ItemCommand(source, e);
        }

        protected override void OnInit(EventArgs e)
        {
            if (this.SkinName == null)
            {
                this.SkinName = "/ascx/tags/Common_ShoppingCart/Skin-Common_ShoppingCart_ProductList.ascx";
            }
            base.OnInit(e);
        }

        public void ShowProductCart()
        {
            if (this.isNull)
            {
                this.pnlShopProductCart.Visible = false;
            }
            else
            {
                this.pnlShopProductCart.Visible = true;
            }
        }

        [Browsable(false)]
        public object DataSource
        {
            get
            {
                return this.dataListShoppingCrat.DataSource;
            }
            set
            {
                if (this.isNull) this.isNull = value == null || ((IList)value).Count == 0;
                this.EnsureChildControls();
                this.dataListShoppingCrat.DataSource = value;
            }
        }

        public override string ID
        {
            get
            {
                return base.ID;
            }
            set
            {
            }
        }
        public Dictionary<string, List<ShoppingCartItemInfo>> Promotions
        {
            get
            {
                return this.promotions;
            }
            set
            {
                if (this.isNull) this.isNull = value == null || value.Count == 0;
                this.promotions = value;
            }
        }
    }
}

